<?php
declare (strict_types = 1);

namespace app\validate\common\order;

use app\model\communal\OrderMultiModel;
use think\Validate;

class MultiValidate extends Validate
{
    /**
     * 定义验证规则
     * 格式：'字段名' =>  ['规则1','规则2'...]
     *
     * @var array
     */
    protected $rule = [
        'id' => ['require', 'number', 'gt:0'],
        'expert_id' => ['require', 'number', 'gt:0'],
        'scale_multi_id' => ['require', 'number', 'gt:0'],
        'consult_at' => ['require', 'number', 'gt:0'],
        'topic_id' => ['require', 'number', 'gt:0'],
        'answer' => ['require', 'number', 'egt:0'],
        'topics' => ['require'],

        /*
         * 付款
         */
        'payment_type' => ['require', 'in:1,2'],
        'is_coin' => ['require', 'in:1,2'],
        // 'deduct_coin' => ['number', 'egt:0'],

        'page' => ['number', 'gt:0'],
        'page_size' => ['number', 'gt:0'],
    ];

    protected $field = [
        'id' => '测试订单',
        'expert_id' => '专家',
        'scale_multi_id' => '多元智能题型',
        'topic_id' => '测试题目',
        'answer' => '测试答案',

        /*
         * 付款
         */
        'payment_type' => '付款方式',
        'is_coin' => '是否使用元心币',


        'page' => '当前页数',
        'page_size' => '每页条数',
    ];

    /**
     * 定义错误信息
     * 格式：'字段名.规则名' =>  '错误信息'
     *
     * @var array
     */
    protected $message = [];

    /**
     * 场景
     * @var array
     */
    protected $scene = [
        'index' => ['page', 'page_size'],
        'topic' => ['id'],
        'id' => ['id'],
        'answer' => ['id', 'topic_id', 'answer'],
        'answers' => ['id', 'topics'],
        'result' => ['id'],
        'interpreter' => ['scale_multi_id'],
        'interpreterRead' => ['scale_multi_id', 'expert_id'],
        'reserve' => ['id', 'consult_at'],
        'repay' => ['id', 'payment_type', 'is_coin'],
    ];

    /**
     * scene save
     *
     * @return $this
     */
    public function sceneSave()
    {
        return $this->only(OrderMultiModel::$saveColumn);
    }

    /**
     * scene update
     *
     * @return $this
     */
    public function sceneUpdate()
    {
        return $this->only(OrderMultiModel::$updateColumn);
    }

    /**
     * scene update
     *
     * @return $this
     */
    public function sceneItem()
    {
        return $this->only(['id']);
    }
}
